<template>
	<view>
		<view class="top-tab-view">
			<view class="left-tab">
				<!-- <view @click="selectedTab('推荐')" class="tab-item" :class="tabSelected==='推荐'? 'tab-selected':''">推荐</view>
				<view @click="selectedTab('最新')" class="tab-item" :class="tabSelected==='最新'? 'tab-selected':''">最新</view>
				<view @click="screen" class="tab-item">筛选</view>
				<view @click="selectedTab('近一个月')" class="tabitem" :class="tabSelected==='近一个月'? 'tab-selected':''">近一个月</view> -->
				<view @click="subTabClick({'classifyName':'全部'})" class="tab-item" :class="classifySelected.classifyName=='全部'? 'tab-selected':''">全部</view>
				<view v-for="(item,index) in subTabs" :key="index" @click="subTabClick(item)" class="tab-item" :class="classifySelected.classifyName==item.classifyName ? 'tab-selected':''">{{ item.classifyName }}</view>
			</view>
			<!-- 	<view class="right-btn">
				<picker mode="date">
					<view>自选</view>
				</picker>
				<image src="../../static/logo.png"></image>
			</view> -->
		</view>

		<view class="list-view">
			<view class="list-item" v-for="item in list" :key="item.uid" @click="goDetails(item)">
				<view class="left">
					<image v-if="item.coverFileName" :src="item.coverFileName"></image>
					<image v-else src="/static/img/yinpintihuan.png"></image>
				</view>
				<view class="right">
					<view class="title">
						<!-- <image src="../../static/logo.png" class="play-icon"></image> -->
						<view class="titleName">{{item.titleName}}</view>
					</view>
					<view class="from-and_date">
						<text v-if="item.origin">{{item.origin}}|</text>
						{{item.releaseTime}}
					</view>
				</view>
			</view>
		</view>
		<view class="isOver" v-if="isOver">{{ overText }}</view>
		<!-- <uni-popup ref="popup" background-color="#fff">
			<view class="popup-content">
				<view class="tab-tit" style="color:#F69A23">
					百姓健康系列栏目
				</view>
				<view @click="subTabClick(ele)" class="sub-tab-item"
					:class="classifyUid === ele.uid ? 'sub-tab-item-selected' : ''"
					v-for="(ele,index) in subTabs" :key="ele.uid">
					{{ele.classifyName}}
				</view>
			</view>
		</uni-popup> -->
	</view>
</template>

<script>
	import * as topNewsList from '../../common/api/topNewsList.js'
	import {baseUrl} from '../../common/config.js'
	export default {
		data() {
			return {
				tabSelected: "最新",
				classifySelected:{
          classifyName: '全部'
        },
				queryForm: {
					columnRecommendation: '是'
				},
				pageIndex: 1,
				pageSize: 10,
				total:0,
				isOver:false,
				overText:'---我是有底线的---',
				list: [],
				classify: "",
				classifyUid: "7b0a2db334574c3c9c4e97c85769c617",
				subTabs: [
					{
						"uid": "025cfacafd3b42e38ef91f6a0b5bde30",
						"classifyName": "《陕西日报》专版",
						url:'/shanxiDaily/queryByPage'
					},
					{
						"uid": "8c5dccb2f8d94657bdb4b69b938b66bf",
						"classifyName": "《三秦百姓健康》杂志",
						url:'/sanqinPerHenlthMagazine/queryByPage'
					},
					{
						"uid": "b6be5556f2884fbcb1447ffd69a1fefe",
						"classifyName": "《陕西老年健康报》专版",
						url:'/senileHealthNews/queryByPage'
					},
					{
						"uid": "959930f21ddf443d9694a1b79168da4a",
						"classifyName": "电视栏目",
						url:'/sysTvColumn/queryByPage'
					},
					{
						"uid": "fa6b29bca3fa47a2919df7bc1b30b992",
						"classifyName": "广播栏目",
						url:'/sysBroadcast/queryByPage'
					},
				],
				map: {
					text: 'classifyName',
					value: 'uid'
				},
				thisUrl:'/healthyDataPublish/queryByPage',
			}
		},
		onLoad(e) {
			this.classify = e.classifyName
			this.getList()
		},
		onReady() {
			uni.setNavigationBarTitle({
				title: '百姓健康系列栏目'
			})
		},
		methods: {
			getList() {
				let data = {
					pageIndex: this.pageIndex,
					pageSize: this.pageSize,
				};
        // if(this.classifySelected.classifyName=='全部'){
        //   // 陕西日报》专版  《三秦百姓健康》杂志 《陕西老年健康报》专版    广播栏目
        //   data.classifyUids=['025cfacafd3b42e38ef91f6a0b5bde30','8c5dccb2f8d94657bdb4b69b938b66bf','b6be5556f2884fbcb1447ffd69a1fefe','fa6b29bca3fa47a2919df7bc1b30b992']
        // }else{
        //   data.classifyUid=this.classifySelected.uid
        // }
				
				uni.request({
					url: baseUrl+this.thisUrl,
					method: 'POST',
					data: data,
					success: (res) => {
						if(res.data.data.rows == null){
							this.list = []
							this.total = 0
							this.isOver = true;
						}else{
							res.data.data.rows.forEach(item=>{
								if(item.titleName == undefined){
									item.coverFileName = item.imgUrl
									item.titleName = item.periods == undefined ? item.wxName : item.periods
									item.releaseTime = item.createTime
								}
							})
							
							this.list = [...this.list,...res.data.data.rows]
							this.total = res.data.data.total;
							if (this.pageIndex * this.pageSize >= this.total) {
								this.isOver = true;
							}
						}
					}
				})
				// const param = {
				// 	pageIndex: this.pageIndex,
				// 	pageSize: this.pageSize,
				// 	// classifyUid: this.classifyUid,
				// 	...this.queryForm
				// }
				// if(this.classifySelected != '全部'){
				// 	param.classify = this.classifySelected;
				// }else{
				// 	param.classifyUid = this.classifyUid;
				// }
				// topNewsList.queryByPage(param).then(res => {
				// 	// this.list = res.data.data.rows
				// 	this.list = [...this.list,...res.data.data.rows]
				// 	this.total = res.data.data.total;
				// 	if (this.pageIndex * this.pageSize >= this.total) {
				// 		this.isOver = true;
				// 	}
				// });
			},
			selectedTab(e) {
				this.tabSelected = e
				if (e === '推荐') {
					this.queryForm = {
						columnRecommendation: '是'
					}
				} else if (e === '最新') {
					this.queryForm = {}
				} else if (e === '近一个月') {
					this.queryForm = {}
				}
				this.getList()
			},
			goDetails(data) {
        if(!data.classify){//陕西老年健康报 不是pdf，需更新getList  
            uni.navigateTo({
            	url: "/pages/peopleHealthList/peopleHealthLaonianList?ptUid=" + data.uid
            })     
          
        }else{
          uni.navigateTo({
          	url: "/pages/details/details?uid=" + data.uid
          })
        }
				
			},
			queryTreeByCode() {//实际没有调用 subTabs 写死了
				const param = {
					code: '3-bxjkxllm',
				}
				topNewsList.queryTreeByCode(param).then(res => {
					// this.localdata = this.removeEmptyChildren(res.data.data)
					this.subTabs = res.data.data[0]['children']
					//debugger
				}).catch(error => {
					console.log(error)
				})
			},
			removeEmptyChildren(node) {
				node.map(item => {
					if (!item.children || item.children.length === 0) {
						delete item.children
					} else {
						let res = item.children
						this.removeEmptyChildren(res)
					}
				})
				return node
			},
			screen() {
				this.$refs.popup.open('top')
			},
			subTabClick(item) {
				this.list = [];
				this.thisUrl = item.url?item.url:'/healthyDataPublish/queryByPage';
				this.pageIndex = 1;
				this.classifySelected = item;
				this.getList()
			}
		},
		// 下拉
		onReachBottom () {
			if (this.pageIndex * this.pageSize >= this.total) {
				this.isOver = true;
				return;
			} else {
				this.pageIndex++
				this.getList();
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: white;
		display: flex;
		flex-direction: column;
	}

	.top-tab-view {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-bottom:20rpx;
		position: fixed;
		background: #f5f5f5;

		.left-tab {
			display: flex;
			align-items: center;
			flex-wrap: wrap;

			.tab-item {
				// width: 116rpx;
				padding:4rpx 10rpx;
				height: 48rpx;
				margin-top:20rpx;
				margin-left: 30rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 24rpx;
				border-radius: 10rpx;
				background: rgba(48, 177, 141, 0.2);
				color: #30B18D;
			}

			.tab-selected {
				background: #27A280;
				color: #fff;
			}
		}

		.right-btn {
			display: flex;
			align-items: center;
			font-size: 24rpx;
			color: #CCCCCC;

			image {
				width: 32rpx;
				height: 32rpx;
				margin-right: 30rpx;
				margin-left: 10rpx;
			}
		}
	}
	
	.list-view {
		width: 100%;
		display: flex;
		flex-direction: column;
		padding:100rpx 30rpx 0 30rpx;
		box-sizing: border-box;

		.list-item {
			width: 100%;
			display: flex;
			padding: 70rpx 0 30rpx 0;
			border-bottom: solid 1rpx #F5F7F7;

			.left {
				image {
					width: 180rpx;
					height: 135rpx;
					border-radius: 16rpx;
				}
			}

			.right {
				flex: 1;
				margin-left: 30rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.title {
					width: 480rpx;
					color: #666666;
					font-size: 30rpx;
					font-weight: 500;
					display: flex;
					align-items: center;

					.play-icon {
						width: 26rpx;
						height: 20rpx;
						margin-right: 20rpx;
					}

					.titleName {
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
				}

				.from-and_date {
					color: #999999;
					font-size: 24rpx;
				}
			}
		}
	}

	.tab-tit {
		margin: 20rpx;
		font-size: 30rpx
	}

	.sub-tab-item {
		display: inline-block;
		line-height: 48rpx;
		height: 48rpx;
		color: #999999;
		margin: 23rpx 40rpx;
	}

	.sub-tab-item-selected {
		color: #333333;
		border-bottom: solid 4rpx #27A280;
	}
	.isOver{
		text-align: center;
		font-size: 12px;
		color:#bbb;
		height:60rpx;
		line-height:60rpx;
	}
</style>